<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>login</title>
    <script src="Scripts/jquery-1.5.1.js" type="text/javascript"></script>
  <script type="text/javascript" language="JavaScript">

   $(function () {

      $("#submit").click(function () {

        var returnValue = true;

          var txtName = $("#userNameInput").val();
          var txtPassword = $("#userPasswordInput").val();

          var db = getCurrentDb();

//"SELECT * FROM usertable where username='".$nameInput."'"
//if exists (select * from sysdatabases where name='databaseName')
          db.transaction(function (trans) {
               trans.executeSql("select * from Register where  userName=?", [txtName], function (ts, data) {
                    if (data) {
                             for (var i = 0; i < data.rows.length; i++) {
                                var row =data.rows.item(i);//获取某行数据的json对象
                                if (row.userPassword==txtPassword){
                                    alert("登录成功！");
                                    returnValue=true;
                                    window.location.href="showData.html";
                                    return;
                                  }
                             }
                            alert("账号或密码错误！");
                            returnValue=false;
                            return;
                        
                      }

                   
                }, function (ts, message) {
                    alert(message);
                    var tst = message;
                });


            });
          return returnValue;
      });
  });

  function getCurrentDb() {
      //打开数据库，或者直接连接数据库参数：数据库名称，版本，概述，大小
      var db = openDatabase("myDb", "1.0", "it's to save register data!", 1024 * 1024); ;
      return db;
       
  }

  </script>
    <link rel="stylesheet" href="weui.min.css">
    <link rel="stylesheet" href="weui.css">

</head>
<body ontouchstart>
<div class="page" style="text-align:center;top:20%;">
        <div class="page__hd">
        <h1 class="page__title">
            <img src="icon.jpg" height="180px" />
        </h1>
    </div>

        <div class="weui-cells__title">登录</div>
        <div class="weui-cells weui-cells_form" >
            <div class="weui-cell" style="left:40%">
                <div class="weui-cell__hd"><label class="weui-label">用户名</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" name="userNameInput" id="userNameInput" size="20" placeholder="请输入用户名"/>
                </div>
            </div>

        </div>
            <div class="weui-cells  weui-cells_form">
            <div class="weui-cell" style="left:40%">
                <div class="weui-cell__hd">
                    <label class="weui-label">密码</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="password"  maxlength="20" name="userPasswordInput" id="userPasswordInput" placeholder="请输入密码"/>
                </div>
                </div>
            </div>
            
        </div>

        <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary"  name="submit" id="submit" style="width:30%">登录</a>
        </div>
    </div>
</div>

</body>
</html>
